/*   1:    */ package org.intellij.plugins.relaxNG.model.resolve;
/*   2:    */ 
/*   3:    */

import com.intellij.navigation.ColoredItemPresentation;
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.NavigationItem;
import com.intellij.navigation.PsiElementNavigationItem;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.meta.PsiMetaData;
import com.intellij.psi.meta.PsiMetaOwner;
import com.intellij.psi.meta.PsiPresentableMetaData;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.indexing.*;
import com.intellij.util.indexing.FileBasedIndex.InputFilter;
import com.intellij.util.indexing.FileBasedIndex.ValueProcessor;
import com.intellij.util.io.EnumeratorStringDescriptor;
import com.intellij.util.io.KeyDescriptor;
import org.intellij.plugins.relaxNG.compact.RncFileType;
import org.intellij.plugins.relaxNG.model.Define;
import org.intellij.plugins.relaxNG.model.Grammar;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Collection;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */
/*  30:    */
/*  31:    */
/*  32:    */
/*  33:    */
/*  34:    */
/*  35:    */
/*  36:    */
/*  37:    */
/*  38:    */
/*  39:    */
/*  40:    */
/*  41:    */
/*  42:    */
/*  43:    */
/*  44:    */
/*  45:    */
/*  46:    */
/*  47:    */
/*  48:    */ 
/*  49:    */ public class RelaxSymbolIndex
/*  50:    */   extends ScalarIndexExtension<String>
/*  51:    */ {
/*  52:    */   @NonNls
/*  53: 60 */   public static final ID<String, Void> NAME = ID.create("RelaxSymbolIndex");
/*  54:    */   
/*  55:    */   public static Collection<String> getSymbolNames(Project paramProject)
/*  56:    */   {
/*  57: 63 */     return FileBasedIndex.getInstance().getAllKeys(NAME, paramProject);
/*  58:    */   }
/*  59:    */   
/*  60:    */   public static NavigationItem[] getSymbolsByName(String paramString, Project paramProject, boolean paramBoolean)
/*  61:    */   {
/*  62: 67 */     GlobalSearchScope localGlobalSearchScope = paramBoolean ? GlobalSearchScope.allScope(paramProject) : GlobalSearchScope.projectScope(paramProject);
/*  63: 68 */     SymbolCollector localSymbolCollector = new SymbolCollector(paramString, paramProject, localGlobalSearchScope);
/*  64: 69 */     FileBasedIndex.getInstance().processValues(NAME, paramString, null, localSymbolCollector, localGlobalSearchScope);
/*  65: 70 */     return localSymbolCollector.getResult();
/*  66:    */   }
/*  67:    */   
/*  68:    */   @NotNull
/*  69:    */   public ID<String, Void> getName()
/*  70:    */   {
/*  71: 76 */     ID tmp3_0 = NAME;
/*  72: 76 */     if (tmp3_0 == null) {
/*  73: 76 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/model/resolve/RelaxSymbolIndex", "getName" }));
/*  74:    */     }
/*  75: 76 */     return tmp3_0;
/*  76:    */   }
/*  77:    */   
/*  78:    */   @NotNull
/*  79:    */   public DataIndexer<String, Void, FileContent> getIndexer()
/*  80:    */   {
/*  81: 82 */     void tmp8_5 = new DataIndexer();
/*  82: 82 */     if (tmp8_5 == null) {
/*  83: 82 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/model/resolve/RelaxSymbolIndex", "getIndexer" }));
/*  84:    */     }
/*  85: 82 */     return tmp8_5;
/*  86:    */   }
/*  87:    */   
/*  88:    */   @NotNull
/*  89:    */   public KeyDescriptor<String> getKeyDescriptor()
/*  90:    */   {
/*  91:150 */     void tmp7_4 = new EnumeratorStringDescriptor();
/*  92:150 */     if (tmp7_4 == null) {
/*  93:150 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/model/resolve/RelaxSymbolIndex", "getKeyDescriptor" }));
/*  94:    */     }
/*  95:150 */     return tmp7_4;
/*  96:    */   }
/*  97:    */   
/*  98:    */   @NotNull
/*  99:    */   public FileBasedIndex.InputFilter getInputFilter()
/* 100:    */   {
/* 101:156 */     void tmp24_21 = new DefaultFileTypeSpecificInputFilter(new FileType[] { StdFileTypes.XML, RncFileType.getInstance() });
/* 102:156 */     if (tmp24_21 == null) {
/* 103:156 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/model/resolve/RelaxSymbolIndex", "getInputFilter" }));
/* 104:    */     }
/* 105:156 */     return tmp24_21;
/* 106:    */   }
/* 107:    */   
/* 108:    */   public boolean dependsOnFileContent()
/* 109:    */   {
/* 110:166 */     return true;
/* 111:    */   }
/* 112:    */   
/* 113:    */   public int getVersion()
/* 114:    */   {
/* 115:171 */     return 0;
/* 116:    */   }
/* 117:    */   
/* 118:    */   private static class SymbolCollector
/* 119:    */     implements FileBasedIndex.ValueProcessor<Void>
/* 120:    */   {
/* 121:    */     private final GlobalSearchScope a;
/* 122:    */     private final PsiManager b;
/* 123:    */     private final String c;
/* 124:179 */     private final Collection<NavigationItem> d = new ArrayList();
/* 125:    */     
/* 126:    */     public SymbolCollector(String paramString, Project paramProject, GlobalSearchScope paramGlobalSearchScope)
/* 127:    */     {
/* 128:182 */       this.b = PsiManager.getInstance(paramProject);
/* 129:183 */       this.a = paramGlobalSearchScope;
/* 130:184 */       this.c = paramString;
/* 131:    */     }
/* 132:    */     
/* 133:    */     public boolean process(VirtualFile paramVirtualFile, Void paramVoid)
/* 134:    */     {
/* 135:189 */       if (this.a.contains(paramVirtualFile))
/* 136:    */       {
/* 137:190 */         PsiFile localPsiFile = this.b.findFile(paramVirtualFile);
/* 138:191 */         if ((localPsiFile instanceof XmlFile))
/* 139:    */         {
/* 140:192 */           Grammar localGrammar = GrammarFactory.getGrammar((XmlFile)localPsiFile);
/* 141:193 */           if (localGrammar != null) {
/* 142:194 */             localGrammar.acceptChildren(new CommonElement.Visitor()
/* 143:    */             {
/* 144:    */               public void visitDefine(Define paramAnonymousDefine)
/* 145:    */               {
/* 146:197 */                 if (RelaxSymbolIndex.SymbolCollector.this.c.equals(paramAnonymousDefine.getName()))
/* 147:    */                 {
/* 148:198 */                   PsiElement localPsiElement = paramAnonymousDefine.getPsiElement();
/* 149:199 */                   if (localPsiElement != null) {
/* 150:200 */                     RelaxSymbolIndex.MyNavigationItem.add((NavigationItem)paramAnonymousDefine.getPsiElement(), RelaxSymbolIndex.SymbolCollector.this.d);
/* 151:    */                   }
/* 152:    */                 }
/* 153:    */               }
/* 154:    */             });
/* 155:    */           }
/* 156:    */         }
/* 157:    */       }
/* 158:208 */       return true;
/* 159:    */     }
/* 160:    */     
/* 161:    */     public NavigationItem[] getResult()
/* 162:    */     {
/* 163:212 */       return (NavigationItem[])this.d.toArray(new NavigationItem[this.d.size()]);
/* 164:    */     }
/* 165:    */   }
/* 166:    */   
/* 167:    */   private static class MyNavigationItem
/* 168:    */     implements PsiElementNavigationItem, ItemPresentation
/* 169:    */   {
/* 170:    */     private final NavigationItem a;
/* 171:    */     private final ItemPresentation b;
/* 172:    */     
/* 173:    */     private MyNavigationItem(NavigationItem paramNavigationItem, @NotNull ItemPresentation paramItemPresentation)
/* 174:    */     {
/* 175:221 */       this.a = paramNavigationItem;
/* 176:222 */       this.b = paramItemPresentation;
/* 177:    */     }
/* 178:    */     
/* 179:    */     public String getPresentableText()
/* 180:    */     {
/* 181:227 */       return this.b.getPresentableText();
/* 182:    */     }
/* 183:    */     
/* 184:    */     @Nullable
/* 185:    */     public String getLocationString()
/* 186:    */     {
/* 187:233 */       return a((PsiElement)this.a);
/* 188:    */     }
/* 189:    */     
/* 190:    */     private static String a(PsiElement paramPsiElement)
/* 191:    */     {
/* 192:237 */       return "(in " + paramPsiElement.getContainingFile().getName() + ")";
/* 193:    */     }
/* 194:    */     
/* 195:    */     @Nullable
/* 196:    */     public Icon getIcon(boolean paramBoolean)
/* 197:    */     {
/* 198:243 */       return this.b.getIcon(paramBoolean);
/* 199:    */     }
/* 200:    */     
/* 201:    */     @Nullable
/* 202:    */     public TextAttributesKey getTextAttributesKey()
/* 203:    */     {
/* 204:248 */       return (this.b instanceof ColoredItemPresentation) ? ((ColoredItemPresentation)this.b).getTextAttributesKey() : null;
/* 205:    */     }
/* 206:    */     
/* 207:    */     public String getName()
/* 208:    */     {
/* 209:253 */       return this.a.getName();
/* 210:    */     }
/* 211:    */     
/* 212:    */     public ItemPresentation getPresentation()
/* 213:    */     {
/* 214:258 */       return this;
/* 215:    */     }
/* 216:    */     
/* 217:    */     public PsiElement getTargetElement()
/* 218:    */     {
/* 219:263 */       return (PsiElement)this.a;
/* 220:    */     }
/* 221:    */     
/* 222:    */     public void navigate(boolean paramBoolean)
/* 223:    */     {
/* 224:268 */       this.a.navigate(paramBoolean);
/* 225:    */     }
/* 226:    */     
/* 227:    */     public boolean canNavigate()
/* 228:    */     {
/* 229:273 */       return this.a.canNavigate();
/* 230:    */     }
/* 231:    */     
/* 232:    */     public boolean canNavigateToSource()
/* 233:    */     {
/* 234:278 */       return this.a.canNavigateToSource();
/* 235:    */     }
/* 236:    */     
/* 237:    */     public static void add(final NavigationItem paramNavigationItem, Collection<NavigationItem> paramCollection)
/* 238:    */     {
/* 239:    */       Object localObject;
/* 240:283 */       if ((paramNavigationItem instanceof PsiMetaOwner))
/* 241:    */       {
/* 242:284 */         PsiMetaData localPsiMetaData = ((PsiMetaOwner)paramNavigationItem).getMetaData();
/* 243:285 */         if ((localPsiMetaData instanceof PsiPresentableMetaData))
/* 244:    */         {
/* 245:286 */           PsiPresentableMetaData localPsiPresentableMetaData = (PsiPresentableMetaData)localPsiMetaData;
/* 246:287 */           localObject = new ColoredItemPresentation()
/* 247:    */           {
/* 248:    */             public String getPresentableText()
/* 249:    */             {
/* 250:290 */               return this.val$metaData.getName();
/* 251:    */             }
/* 252:    */             
/* 253:    */             @Nullable
/* 254:    */             public String getLocationString()
/* 255:    */             {
/* 256:296 */               return RelaxSymbolIndex.MyNavigationItem.a((PsiElement)paramNavigationItem);
/* 257:    */             }
/* 258:    */             
/* 259:    */             @Nullable
/* 260:    */             public Icon getIcon(boolean paramAnonymousBoolean)
/* 261:    */             {
/* 262:302 */               return this.val$metaData.getIcon();
/* 263:    */             }
/* 264:    */             
/* 265:    */             @Nullable
/* 266:    */             public TextAttributesKey getTextAttributesKey()
/* 267:    */             {
/* 268:308 */               ItemPresentation localItemPresentation = paramNavigationItem.getPresentation();
/* 269:309 */               return (localItemPresentation instanceof ColoredItemPresentation) ? ((ColoredItemPresentation)localItemPresentation).getTextAttributesKey() : null;
/* 270:    */             }
/* 271:    */           };
/* 272:    */         }
/* 273:    */         else
/* 274:    */         {
/* 275:313 */           localObject = paramNavigationItem.getPresentation();
/* 276:    */         }
/* 277:    */       }
/* 278:    */       else
/* 279:    */       {
/* 280:316 */         localObject = paramNavigationItem.getPresentation();
/* 281:    */       }
/* 282:319 */       if (localObject != null) {
/* 283:320 */         paramCollection.add(new MyNavigationItem(paramNavigationItem, (ItemPresentation)localObject));
/* 284:    */       }
/* 285:    */     }
/* 286:    */   }
/* 287:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.model.resolve.RelaxSymbolIndex

 * JD-Core Version:    0.7.0.1

 */